package com.ruoyi.cloudpc.controller;

import com.ruoyi.cloudpc.domain.CloudWithdrawal;
import com.ruoyi.cloudpc.service.ICloudWithdrawalService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 提现记录Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/system/withdrawal")
public class CloudWithdrawalController extends BaseController {
    @Autowired
    private ICloudWithdrawalService cloudWithdrawalService;

    /**
     * 查询提现记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:list')")
    @GetMapping("/list")
    public TableDataInfo list(CloudWithdrawal cloudWithdrawal) {
        startPage();
        List<CloudWithdrawal> list = cloudWithdrawalService.selectCloudWithdrawalList(cloudWithdrawal);
        return getDataTable(list);
    }

    /**
     * 导出提现记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:export')")
    @Log(title = "提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CloudWithdrawal cloudWithdrawal) {
        List<CloudWithdrawal> list = cloudWithdrawalService.selectCloudWithdrawalList(cloudWithdrawal);
        ExcelUtil<CloudWithdrawal> util = new ExcelUtil<CloudWithdrawal>(CloudWithdrawal.class);
        util.exportExcel(response, list, "提现记录数据");
    }

    /**
     * 获取提现记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cloudWithdrawalService.selectCloudWithdrawalById(id));
    }

    /**
     * 新增提现记录
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CloudWithdrawal cloudWithdrawal) {
        return toAjax(cloudWithdrawalService.insertCloudWithdrawal(cloudWithdrawal));
    }

    /**
     * 修改提现记录
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:edit')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CloudWithdrawal cloudWithdrawal) {
        return toAjax(cloudWithdrawalService.updateCloudWithdrawal(cloudWithdrawal));
    }

    /**
     * 删除提现记录
     */
//    @PreAuthorize("@ss.hasPermi('system:withdrawal:remove')")
    @Log(title = "提现记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(cloudWithdrawalService.deleteCloudWithdrawalByIds(ids));
    }

}
